﻿using MediatR;
using S.Organization.Domian.dto;
using S.Organization.Domian.Model;
using S.Organization.Infrastructure;
using S.Organization.Read.API.Application.Command.CottageCommand;

namespace S.Organization.Read.API.Application.CommandHandler.CottageCommandHandler
{
    public class GetCotCommandHandler : IRequestHandler<GetCotCommand, List<DTO>>
    {
        private readonly IBaseRepository<CottageSetting> _repository;


        public GetCotCommandHandler(IBaseRepository<CottageSetting> repository)
        {
            _repository = repository;
        }

      
        public async Task<List<DTO>> Handle(GetCotCommand request, CancellationToken cancellationToken)
        {
            var list = await _repository.GetAllAsync();
            List<DTO> result = new List<DTO>();
        
            foreach (var item in list)
            {
                DTO data = new DTO();
                data.Id=item.CottageId;
                data.Name=item.CottageName;
                result.Add(data);
            }
            return result;
        }
    }
}
